package com.carryGo.service.dp;

import com.carryGo.dao.dp.UserDao;
import com.carryGo.entity.Commodity;
import com.carryGo.entity.PageManager;
import com.carryGo.entity.ShoppCart;

import java.util.List;

/**
 * ClassName:CommodityService
 * package:guoban
 * Desription:
 *
 * @Date:2020/8/27 14:15
 * @Author: 邓攀
 */
public class CommodityService extends UserDao {

    /**
     * 食品分页查询
     */
    public List<Commodity> queryCommodities(PageManager pm) {
        int start = (pm.getPn()-1) * pm.getRn();
        int end = pm.getRn();
        String sql = "select * from commodity where type = '食品' limit ?,?" ;
        return findList(Commodity.class, sql, start, end);
    }
    public List<Commodity> queryCommodity(PageManager pm) {
        int start = (pm.getPn()-1) * pm.getRn();
        int end = pm.getRn();
        String sql = "select * from commodity limit ?,?";
        return findList(Commodity.class, sql, start, end);
    }


    /**
     * 查询数据的条数
     */
    public int queryUserTotalCount() {
        String sql = "select count(0) from commodity where type = '食品'";
        return count(sql);
    }
    public int queryTotalCount() {
        String sql = "select count(0) from commodity";
        return count(sql);
    }

    /**
     * 食品分页查询
     */
    public List<Commodity> queryCommodityVehicle(PageManager pm) {
        int start = (pm.getPn()-1) * pm.getRn();
        int end = pm.getRn();
        String sql = "select * from commodity where type = '交通工具' limit ?,?" ;
        return findList(Commodity.class, sql, start, end);
    }
    public List<Commodity> queryCommodityVehicle() {
        String sql = "select * from commodity where type = '交通工具'";
        return findList(Commodity.class, sql);
    }

    /**
     * 查询数据的条数
     */
    public int queryVehicleTotalCount() {
        String sql = "select count(0) from commodity where type = '交通工具'";
        return count(sql);
    }

    /**
     * 根据id查询商品
     */
    public Commodity queryCommodity(int id) {
        String sql = "select * from commodity where id = ?";
        return findBean(Commodity.class, sql, id);
    }
    public ShoppCart queryShoppCart(int id) {
        String sql = "select * from shoppcart where id = ?";
        return findBean(ShoppCart.class, sql, id);
    }

    /**
     * 根据用户名查询
     */
    public List<ShoppCart> queryShoppCart(String name) {
        String sql = "select * from shoppcart where userName = ?";
        return findList(ShoppCart.class, sql, name);
    }
}
